<?php
/**
 * Created by PhpStorm.
 * User: 84071
 * Date: 2017-09-07
 * Time: 11:47
 */
namespace app\common\model;
use think\Model;
class Chinacode extends Model{
    /**
     * @param string $zoneid 获取要查询的ID
     * @return array|string 返回下级地区
     */
    public function get_don($data = ''){
        if(empty($data)){
            $dondata = $this->where('parzoneid','0')->select();
        }elseif($data['type'] == 'num'){
            $dondata = $this->where('parzoneid',$data['zoneid'])->select();
        }else{
            $zoneid = $this->where('zonename',$data['zonename'])->value('zoneid');
            $dondata = $this->where('parzoneid',$zoneid)->select();
        }

        foreach ($dondata as $k => $v){
            $dondata[$k] = $v->toArray();
        }
        return $dondata;
    }

    /**
     * @param $zoneid  获取要查询的ID
     * @return array|string 返回所有同级别信息
     */
    public function get_this($data){
        if($data['type'] == 'num'){
            $parzoneid['zoneid'] = $this->where('zoneid',$data['zoneid'])->value('parzoneid');
        }else{
            $parzoneid['zoneid'] = $this->where('zonename',$data['zonename'])->value('parzoneid');
        }
        $parzoneid['type'] = 'num';
        $dondata = $this->get_don($parzoneid);
        return $dondata;
    }

}